package MultiThread;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import javax.swing.text.html.HTMLEditorKit;

import SingleThread.ParserGetter;

public class Processor extends Thread{
	Spider sp;
	
	
	public Processor(Spider spi) {
		sp = spi;
	}

	
	public void run() {
		URL curr;
		ParserGetter kit = new ParserGetter();
		HTMLEditorKit.Parser parser = kit.getParser();
		HTMLEditorKit.ParserCallback callback = new LinkGetter(sp);
		while(sp.cont()) {
			curr = sp.getURL();
			try {
				InputStream in;
				in = new BufferedInputStream(curr.openStream());
				InputStreamReader r = new InputStreamReader(in);
				parser.parse(r, callback, true);
			} catch (IOException e) {
				continue;				
			}
		}
	}
}
